package server

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go-base/src/configs"
	"go-base/src/logs"
)

//启动服务
func StartServer(r *gin.Engine) (string, error) {
	var err error
	Addr := fmt.Sprintf("%s:%d", configs.Conf.BindIp, configs.Conf.BindPort)
	if configs.Conf.UseHttps {
		logs.Info.Println("HTTPS服务器启动成功!!!")
		if err = r.RunTLS(Addr, configs.Conf.Cert, configs.Conf.Key); err != nil {
			return "启动https服务器失败,%s", err
		}
	} else {
		logs.Info.Println("HTTP服务器启动成功!!!")
		if err = r.Run(Addr); err != nil {
			return "启动http服务器失败,%s", err
		}
	}
	return "", nil
}
